
import java.io.IOException;
import java.io.InputStream;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import java.util.*;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author maych
 */
public class XmlHandler extends DefaultHandler{

    private SvgAnimatorMidlet midlet;
    private Player p;
  private Vector nodes = new Vector();
  private Stack tagStack = new Stack();
  private static final String audio = "audio";
  private static final String xlink = "xlink:href";
  private static final String type = "type";
  String attribute1="";
  String attribute2="";

  public XmlHandler (SvgAnimatorMidlet midlet)
  {
    this.midlet = midlet;
  }
  public void startDocument() throws SAXException {

      System.out.println("startDocument");
  }

  public void startElement(String uri, String localName, String qName,
    Attributes attributes) throws SAXException
  {
     

    if(audio.equals(qName))
    {
        System.out.println("qname");
        System.out.println(qName);
        attribute1 = attributes.getValue(xlink);
        System.out.println("ATTRIBUTE");
        System.out.println(attribute1);
        attribute2 = attributes.getValue(type);
        System.out.println("TYPE");
        System.out.println(attribute2);
   
        tagStack.push(qName);
        play();
    }
    
   
  }


  public void characters(char[] ch, int start, int length) throws SAXException
  {
    
  }

   public void endElement(String uri, String localName, String qName,
    Attributes attributes) throws SAXException
  {
    tagStack.pop();
  }
public void endDocument() throws SAXException
  {
    System.out.println("endDocument");
  }


public void play()
{
      try {
        InputStream is = getClass().getResourceAsStream(attribute1);
        p = Manager.createPlayer(is, attribute2);
        p.setLoopCount(5);
        p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
 }
}

